﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Vds2465Telegrams;

namespace Vds2465Parser
{
    internal static class GenParse_DisruptionCode
    {
        #region private constants

        private const byte LowVoltageByte = 0x01;
        private const byte AccumulatorErrorByte = 0x02;
        private const byte NetworkErrorByte = 0x03;
        private const byte PrimaryTransmissionErrorByte = 0x17;
        private const byte SecondaryTransmissionErrorByte = 0x18;

        #endregion private constants

        #region internal methods

		//internal static byte GenerateByte(eDisruptionCode disruptionCode)
		//{
		//    byte disruptionCodeByte = 0x0;

		//    switch (disruptionCode)
		//    {
		//        case eDisruptionCode.AccumulatorError:
		//            disruptionCodeByte = AccumulatorErrorByte;
		//            break;
		//        case eDisruptionCode.LowVoltage:
		//            disruptionCodeByte = LowVoltageByte;
		//            break;
		//        case eDisruptionCode.NetworkError:
		//            disruptionCodeByte = NetworkErrorByte;
		//            break;
		//        case eDisruptionCode.PrimaryTransmissionError:
		//            disruptionCodeByte = PrimaryTransmissionErrorByte;
		//            break;
		//        case eDisruptionCode.SecondaryTransmissionError:
		//            disruptionCodeByte = SecondaryTransmissionErrorByte;
		//            break;
               
		//        default:
		//            // TODO handle error (unknown value for disruptionCode)
		//            break;
		//    }

		//    return disruptionCodeByte;
		//}

        internal static bool ParseByte(byte disruptionCodeByte, out eDisruptionCode disruptionCode)
        {
            // set default value
            bool bRetVal = true;
            disruptionCode = eDisruptionCode.LowVoltage;

            switch (disruptionCodeByte)
            {
                case LowVoltageByte:
                    disruptionCode = eDisruptionCode.LowVoltage;
                    break;
                case AccumulatorErrorByte:
                    disruptionCode = eDisruptionCode.AccumulatorError;
                    break;
                case NetworkErrorByte:
                    disruptionCode = eDisruptionCode.NetworkError;
                    break;
                case PrimaryTransmissionErrorByte:
                    disruptionCode = eDisruptionCode.PrimaryTransmissionError;
                    break;
                case SecondaryTransmissionErrorByte:
                    disruptionCode = eDisruptionCode.SecondaryTransmissionError;
                    break;

                default:
                    // TODO handle error (unknown value for disruptionCodeByte)
                    bRetVal = false;
                    break;
            }

            return bRetVal;
        }

        #endregion internal methods
    }
}
